package com.kmlitro.tag;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.kmlitro.entity.Abastecimento;
import com.kmlitro.entity.dao.AbastecimentoDAO;

public class GetAbastecimentosTag extends TagSupport {

	private static final long serialVersionUID = 6482649531903728539L;
	
	private int vehicleId;
	
	private int userId;
	
	private String var;

	public int getVehicleId() {
		return vehicleId;
	}

	public void setVehicleId(int vehicleId) {
		this.vehicleId = vehicleId;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}
	
	public int doStartTag() throws JspException {
		
		List<Abastecimento> abastecimentos = new ArrayList<Abastecimento>();
		
		try {
			if ((-1 != vehicleId) && (vehicleId > 0)) {
				AbastecimentoDAO aDAO = new AbastecimentoDAO();
				abastecimentos = aDAO.selectAbastecimentosPorVeiculo(userId, vehicleId);
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		pageContext.getRequest().setAttribute(var, abastecimentos);
		
		return SKIP_BODY;
	}
	

}
